package com.lyy.assess;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.example.third.BasicActivity;
import com.example.third.R;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ListView;


public class AssessActivity extends Activity {
	String url = "http://10.204.1.45:8080/StoreDetail/storeSevlet";
	ListView listView;
	AssessAdapter myAdapter;
	List<AssessBean> list;
	Button basic;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.assess);
       basic=(Button) findViewById(R.id.basic);
        
        basic.setOnClickListener(new OnClickListener() {
			Intent intent;
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				intent=new Intent(AssessActivity.this,BasicActivity.class);
				startActivity(intent);
			}
		});
        initView();
        initData();
       
    }
	private void initData() {
		// TODO Auto-generated method stub
		HttpUtils utils = new HttpUtils();
		RequestParams params = new RequestParams();
		params.addBodyParameter("flag", "5");
		params.addBodyParameter("p_id", "1");
		utils.send(HttpMethod.POST, url, params,new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				// TODO Auto-generated method stub
				Log.e("xu", "fail-->" + arg1);
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				// TODO Auto-generated method stub
				String result = arg0.result;
				Log.e("result", result);
				Gson gson = new Gson();
				Type typeOfT = new TypeToken<List<AssessBean>>() {
				}.getType();
				List<AssessBean> resultList = gson.fromJson(result, typeOfT);
				list.addAll(resultList);
				Log.e("xu", list.toString());
				myAdapter.notifyDataSetChanged();
			}
		});
	}
	private void initView() {
		// TODO Auto-generated method stub
		list = new ArrayList<AssessBean>();
		listView = (ListView) findViewById(R.id.assess_listview);
		myAdapter = new AssessAdapter(AssessActivity.this, list);
		listView.setAdapter(myAdapter);
	}


}
